﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JHT.ABPLearn.Tasks.Dto
{
    public class TaskDtoMapping : IDtoMapping
    {
        public void CreateMapping(IMapperConfigurationExpression mapperConfig)
        {
            //定义单向映射
            mapperConfig.CreateMap<CreateTaskInput, ABPTasks>()
                .ForMember(p => p.Id, opt => opt.Ignore())
                .ForMember(p => p.AssignedPerson, opt => opt.Ignore())
                .ForMember(p => p.CreationTime, opt => opt.Ignore());

            mapperConfig.CreateMap<UpdateTaskInputDto, ABPTasks>();
            mapperConfig.CreateMap<TaskDto, UpdateTaskInputDto>();

            //自定义映射
            var taskDtoMapper = mapperConfig.CreateMap<ABPTasks, TaskDto>();
            taskDtoMapper.ForMember(dto => dto.AssignedPersonName, map => map.MapFrom(m => m.AssignedPerson.FullName));
        }
    }
}
